package cn.baker.redssion.delayqueue.service.impl;

import cn.baker.delayqueue.service.RedisDelayQueueHandle;
import cn.baker.redssion.delayqueue.entity.TestDelayQueueDTO;
import cn.baker.redssion.delayqueue.enums.RedisDelayQueueEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 测试延迟队列
 *
 * @author yuanyu
 */
@Slf4j
@Service
public class TestDelayQueue implements RedisDelayQueueHandle<TestDelayQueueDTO> {

    @Override
    public String queueCode() {
        return RedisDelayQueueEnum.TEST_DELAY_QUEUE.getCode();
    }

    @Override
    public Class<TestDelayQueueDTO> getDtoClass() {
        return TestDelayQueueDTO.class;
    }

    @Override
    public void execute(TestDelayQueueDTO dto) {
        long currentTimeMillis = System.currentTimeMillis();
        long time = dto.getTime() + dto.getDelay() - currentTimeMillis;
        log.info("误差,time={}ms", time);
    }
}